from django.contrib import admin

# Register your models here.

from TestModel.models import Test,Contact,Tag

#内联操作
class TagInline(admin.TabularInline):
    model = Tag


class ContactAdmin(admin.ModelAdmin):
    #在顶部增加搜索栏，支持模糊搜索
    search_fields = ('name',)
    #列表中出现 的字段
    list_display = ('name', 'age', 'email')  # list
    inlines = [TagInline]  # Inline

# Register your models here.
# class ContactAdmin(admin.ModelAdmin):
    # fields = ('name', 'email')
    #分栏操作，把age 单列一栏
    fieldsets = (
        ['Main', {
            'fields': ('name', 'email'),
        }],
        ['Advance', {
            'classes': ('collapse',),  # CSS
            'fields': ('age',),
        }]
    )
# 自定义表单操作，这个地方确实强大，完全自动实现了数据操作。
# 修改字段内容，感觉像hibernate里的映射关系。内容减少了age属性。
admin.site.register(Contact, ContactAdmin)
# admin.site.register(Tag, TagInline)
admin.site.register([Test ])
# Register your models here.
# admin.site.register(Test)
# admin.site.register([Test, Contact, Tag])
